import React, { Component } from "react";
import story from "./story";
import "./index.css";
export default class index extends Component {
  constructor() {
    super();
    this.state = story.getState();

    this.unsubscribe = story.subscribe(() => {
      this.setState(story.getState());
    });
  }
  componentWillUnmount = () => {
    this.unsubscribe();
  };
  handleChange = () => {
    story.dispatch({
      type: "text1",
      value: this.state.text1 + 1
    });
  };
  handleDelete = () => {
    story.dispatch({
      type: "text1",
      value: this.state.text1 - 1
    });
  };
  render() {
    return (
      <div className="box">
        <p>{this.state.text1}</p>
        <p> {"￥" + this.state.text1}</p>
        <p>{this.state.text1 + ".00"}</p>
        <button onClick={this.handleChange}>+</button>

        <button onClick={this.handleDelete}>-</button>
      </div>
    );
  }
}
